<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
$gid=intval($_GET["gid"]);
if(empty($gid)){
    
    echo "<div class=\"pageHeader\">没有选择产品，请关闭窗口。</div>";
    
    exit; 
}
if($_POST["sub"]=="save"){
    $orgId=$_POST["orgId"];
    $goods_relate=intval($_POST["goods_relate"]);
    if(!empty($orgId)){

         while(list($k,$vid)=each($orgId)){
            $relaterow=$ezhand->select('goods_relate',"id",'relateid="'.$vid.'" and gid="'.$gid.'"');  
            if(empty($hisrow)){
                $data2=array("relateid"=>$vid,"gid"=>$gid,"addtime"=>time(),"relatecatid"=>$goods_relate);
                $ezhand->insert("goods_relate",$data2);
            }
         } 
    }
    jumpajax('200','添加成功','','closeCurrent');
    exit;
}
$catid=trim($_POST["catid"]);
$page = !($_POST['pageNum'])?'1':intval($_POST['pageNum']);
$pagesize= !($_POST['numPerPage'])?'20':intval($_POST['numPerPage']);


if(empty($pagesize)){
    $pagesize=20;
}
$frmnum=($page-1)*$pagesize;
$orderField=trim($_POST["orderField"]);
$orderDirection=trim($_POST["orderDirection"]);
if(empty($orderField)){
    $orderField="id";
}
if(empty($orderDirection)){
    $orderDirection="desc";
}
if($orderField<>""){
    $order=" order by $orderField ".$orderDirection;
}else{
    $order=" order by t.id desc";
}

$q=trim($_POST['q']);
$where=' and t.id<>'.$gid;
$catlistrow=$ezhand->select_all("category",'id,catname','parentid=62');
if(!empty($catid)){
    $where.=' and t.catid='.$catid ; 

}
$where.=" and t.id not in (select relateid from ce_goods_relate where gid=".$gid.")";


$total=$ezhand->count("thread t,category c","t.catid=c.id and t.modelid=11 and  t.title like '%$q%'".$where);
$row=$ezhand->select_all("thread t,category c",'t.*,c.catname','t.catid=c.id and t.modelid=11 and t.title like "%'.$q.'%"'.$where.' '.$order.' limit '.$frmnum.','.$pagesize);



?>